<?php

class guestAction extends CommonAction
{
    public function index()
    {
        $this->display();
    }

    //guest表操作
    public function guestadd()
    {
        $this->display();

    }

    public function guestaddsave()
    {
        $guest = new guestModel();
        if (!$guest->create()) {
            $this->error($guest->getError());
        } else {
            $id = $guest->add();
            $this->assign("jumpUrl", U("guest/guestcontent", array('id' => $id)));
            $this->success("添加成功");
        }
    }

    public function guestlist()
    {
        $guest = new guestModel();
        import("ORG.Util.Page");
        $pagsize = 15;
        $totalnum = $guest->count();
        $list = $guest->page($_GET['p'])->order('id desc')->limit($pagsize)->select();
        $this->assign("list", $list);
        $page = new Page($totalnum, $pagsize);
        $page->rollPage = $pagsize;
        $page->setConfig("prev", "上一页");
        $page->setConfig("next", "下一页");
        $page->setConfig("first", "首页");
        $page->setConfig("last", "末页");
        $page->setConfig("theme", "共%totalRow%%header%条数据 %nowPage%/%totalPage%页  %first% %upPage%   %linkPage%  %downPage% %end%");
        $pageshow = $page->show();
        $this->assign("pageshow", $pageshow);
        $this->display();
    }

    public function guestadmin()
    {
        $guest = new guestModel();
        import("ORG.Util.Page");
        $totalnum = $guest->count();
        $list = $guest->page($_GET['p'])->limit(10)->select();
        $this->assign("list", $list);
        $page = new Page($totalnum, 10);
        $page->rollPage = 10;

        $page->setConfig("prev", "上一页");
        $page->setConfig("next", "下一页");
        $page->setConfig("first", "首页");
        $page->setConfig("last", "末页");
        $page->setConfig("theme", "共%totalRow%%header%条数据 %nowPage%/%totalPage%页  %first% %upPage%   %linkPage%  %downPage% %end%");
        $pageshow = $page->show();
        $this->assign("pageshow", $pageshow);
        $this->display();
    }

    public function guestupdate()
    {
        $guest = new guestModel();
        $data = $guest->where("id='{$_GET['id']}'")->find();
        $this->assign("data", $data);
        $this->display();
    }

    public function guestupdatesave()
    {
        $guest = new guestModel();
        if (!$guest->create()) {
            $this->error($guest->getError());
        } else {
            $guest->save();
            $this->success("修改成功");
        }
    }

    public function guestcontent()
    {
        $guest = new guestModel();
        $data = $guest->where("id='{$_GET['id']}'")->find();
        $this->assign("data", $data);
        $this->display();
    }

    public function guestdel()
    {
        $guest = new guestModel();
        if (!$guest->delete($_GET[''])) {
            $this->error("删除失败");
        } else {
            $this->success("删除成功");
        }
    }

    public function _empty()
    {
        //空操作
        $this->error("您访问的页面不存在！");
    }

}

?>